package org.testfire.realm.model.entities.testfire;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: granum
 * Date: Aug 21, 2007
 * Time: 12:20:25 AM
 */
@Entity
@Table(catalog = "testfire", name = "testset")
public class TestsetEntity
{
	private int id;

	private String name;

	private String description;

	private String username;

	private Timestamp created;

	private Timestamp lastverified;

	private String forbug;

	private List<TagEntity> tags;

	private List<TestEntity> tests;

	private String testsetdata;

	private List<TestRunnerQueueEntity> queues;
	private AgentEntity runningOnAgents;
	private List<AgentEntity> agentHasTestset;
	private List<TestsetResultEntity> results;

	@OneToMany(mappedBy = "testset", cascade = CascadeType.REFRESH )
	public List<TestsetResultEntity> getResults()
	{
		return results;
	}

	public void setResults(List<TestsetResultEntity> results)
	{
		this.results = results;
	}

	@OneToMany(mappedBy = "hastestset", cascade = CascadeType.REFRESH )
	public List<AgentEntity> getAgentHasTestset()
	{
		return agentHasTestset;
	}

	public void setAgentHasTestset(List<AgentEntity> agentHasTestset)
	{
		this.agentHasTestset = agentHasTestset;
	}


	

	@ManyToMany(mappedBy = "testsets", cascade = CascadeType.REFRESH )
	public List<TestRunnerQueueEntity> getQueues()
	{
		return queues;
	}

	public void setQueues(List<TestRunnerQueueEntity> queues)
	{
		this.queues = queues;
	}

	@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH})
	@JoinTable(catalog = "testfire", name = "testset_owns_tests",
			joinColumns = @JoinColumn(name = "testset_id", referencedColumnName = "id", nullable = false),
			inverseJoinColumns = @JoinColumn(name = "test_id", referencedColumnName = "id", nullable = false))
	public List<TestEntity> getTests()
	{
		return tests;
	}

	public void setTests(List<TestEntity> tests)
	{
		this.tests = tests;
	}

	@OneToMany(cascade =  {CascadeType.PERSIST, CascadeType.REFRESH})
	@JoinTable(catalog = "testfire", name = "testset_owns_tags",
			joinColumns = @JoinColumn(name = "testset_id", referencedColumnName = "id", nullable = false),
			inverseJoinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id", nullable = false))
	public List<TagEntity> getTags()
	{
		return tags;
	}

	public void setTags(List<TagEntity> tags)
	{
		this.tags = tags;
	}

	@Basic
	@Column(name = "forBug", nullable = false)
	public String getForbug()
	{
		return forbug;
	}

	public void setForbug(String forbug)
	{
		this.forbug = forbug;
	}

	@Basic
	@Column(name = "lastVerified", nullable = false, length = 19)
	public Timestamp getLastverified()
	{
		return lastverified;
	}

	public void setLastverified(Timestamp lastverified)
	{
		this.lastverified = lastverified;
	}

	public void setCreated(Timestamp created)
	{
		this.created = created;
	}

	@SuppressWarnings({"JpaModelErrorInspection"})
	@Basic
	@Column(name = "created", nullable = false, length = 19)
	public Timestamp getCreated()
	{
		return created;
	}

	@Basic
	@Column(name = "userName", nullable = false)
	public String getUsername()
	{
		return username;
	}

	public void setUsername(String username)
	{
		this.username = username;
	}

	@Basic
	@Column(name = "description", nullable = false, length = 65535)
	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	@Basic
	@Column(name = "name", nullable = false)
	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	@Column(name = "id", nullable = false, length = 10)
	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	@Basic
	@Column(name = "testsetdata", nullable = false, length = 16277215)
	public String getTestsetdata()
	{
		return testsetdata;
	}

	public void setTestsetdata(String testsetdata)
	{
		this.testsetdata = testsetdata;
	}

	@Transient
	public boolean equals(Object obj)
	{
		if (obj instanceof TestsetEntity)
		{
			return this.id == ((TestsetEntity) obj).id;
		}
		return super.equals(obj);
	}
}
